package com.sikao.app.net;

import android.content.Context;


import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;

import dmax.dialog.SpotsDialog;


public abstract class SpotsCallBack<T> extends BaseCallback<T> {


	private Context mContext;

	private SpotsDialog mDialog;

	private boolean isShow;

	public SpotsCallBack(Context context, boolean isShow) {

		mContext = context;
		this.isShow = isShow;
		initSpotsDialog();
	}


	private void initSpotsDialog() {
		if (isShow && mDialog == null) {
			mDialog = new SpotsDialog(mContext, "拼命加载中...");
		}
	}

	public void showDialog() {
		mDialog.show();
	}

	@Override
	public void dismissDialog() {
		if (isShow && mDialog!= null && mDialog.isShowing()) {
			mDialog.dismiss();
			mDialog = null;
		}
	}

	public void setLoadMessage(int resId) {
		mDialog.setMessage(mContext.getString(resId));
	}


	@Override
	public void onFailure(Request request, Exception e) {
		if (request == null){
			onError(null, 1, null);
		}else{
			onError(null, 2, null);
		}
	}

	@Override
	public void onBeforeRequest(Request request) {
		if (isShow) {
			showDialog();
		}
	}

	@Override
	public void onResponse(Response response) {
	}

}
